import os
import shutil

path = 'C:/Users/Administrator/Downloads'
files = os.listdir(path)

for f in files:
    if os.path.isfile(os.path.join(path, f)):
        folder_name = f.split('.')[-1]
        if f != folder_name:
            print(folder_name)
            category_dir_path = os.path.join(path, folder_name)
            file_path = os.path.join(path, f)
            print(category_dir_path)
            if not os.path.exists(category_dir_path):
                os.makedirs(category_dir_path)
                shutil.move(file_path, category_dir_path)
            else:
                shutil.move(file_path, category_dir_path)
